package com.kate.mall.bff.wx.pool;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 新梦想.陈超
 * @version 2021.2
 * @Description: {TODO}
 * @date 2022/7/9 下午4:15
 */
public class ThreadPoolUtils {
    //1.私有化构造方法
    private ThreadPoolUtils(){}
    //2.提供公有获取实例的方法
    public static ThreadPoolExecutor instance(boolean prototype){
      return  prototype?
        new ThreadPoolExecutor(9,9,0L, TimeUnit.SECONDS,new SynchronousQueue<>())
              :LazyHolder.threadPool;
    }
    //3.静态内部类的方式实现单例模式
    private static class LazyHolder{
        private static final ThreadPoolExecutor threadPool =
                new ThreadPoolExecutor(100,1000,0L, TimeUnit.SECONDS,new SynchronousQueue<>());
    }
}